package edu.pdx.cs.cs542s07.minichess;

import java.util.ArrayList;

public class MoveFactoryTest {
	
	static private void testHelper(String stateString)  {
		System.out.println("Begin test");
		Board board = new Board();
		MoveFactory factory = new MoveFactory();
		System.out.println("Board state:\n" + stateString);
		try {
			board.fromString(stateString);	
		} catch (IllegalBoardStringException e) {
			e.printStackTrace();
		}
		System.out.println("Possible moves:");
		printMoves(factory.generateScoredMoves(board));
		System.out.println("End test");
	}
	
	static void printMoves(ArrayList<Move> list) {
		StringBuffer s = new StringBuffer();

		for (Move m: list) {
			Square to = m.getTo();
			Square from = m.getFrom();
			s.append('(');
			s.append(from.row);
			s.append(',');
			s.append(from.col);
			s.append(")->(");
			s.append(to.row);
			s.append(',');
			s.append(to.col);
			s.append("): ");
			s.append(m.getScore());
			System.out.println(s.toString());
			s.delete(0,s.capacity());
		}

		
	}
	
	public static void main(String args[]) {
	
	//test: no pieces (degenerate case)
	String stateString = 	"0 W\n" +
	".....\n" +
	".....\n" +
	".....\n" +
	".....\n" +
	".....\n" +
	".....\n";
	testHelper(stateString);

	
	//test: King only
	stateString = 	"0 W\n" +
	".....\n" +
	".....\n" +
	".....\n" +
	"..K..\n" +
	".....\n" +
	".....\n";
	testHelper(stateString);
	
	//test: King near wall
	stateString = 	"0 W\n" +
	".....\n" +
	".....\n" +
	".....\n" +
	"K....\n" +
	".....\n" +
	".....\n";
	testHelper(stateString);
	
	//test: King adjacent to friendly piece
	stateString = 	"0 W\n" +
	".....\n" +
	".....\n" +
	".P...\n" +
	"K....\n" +
	".....\n" +
	".....\n";
	testHelper(stateString);
	
	//test: King adjacent to enemy piece
	stateString = 	"0 W\n" +
	".....\n" +
	".....\n" +
	".....\n" +
	"K....\n" +
	".q...\n" +
	".....\n";
	testHelper(stateString);

	//test: Queen only
	stateString = 	"0 W\n" +
	".....\n" +
	".....\n" +
	".....\n" +
	"..Q..\n" +
	".....\n" +
	".....\n";
	testHelper(stateString);
	
	//test: Queen near wall
	stateString = 	"0 W\n" +
	".....\n" +
	".....\n" +
	".....\n" +
	".....\n" +
	".....\n" +
	"..Q..\n";	
	testHelper(stateString);
	
	//test: Queen with friendly piece in sight
	stateString = 	"0 W\n" +
	".....\n" +
	".....\n" +
	"..P..\n" +
	"..Q..\n" +
	".....\n" +
	".....\n";	
	testHelper(stateString);
	
	//test: Queen with enemy piece in sight
	stateString = 	"0 W\n" +
	".....\n" +
	".....\n" +
	"...b.\n" +
	"..Q..\n" +
	".....\n" +
	".....\n";
	testHelper(stateString);
	
	
	//test: Rook only
	stateString = 	"0 W\n" +
	".....\n" +
	".....\n" +
	".....\n" +
	"..R..\n" +
	".....\n" +
	".....\n";
	testHelper(stateString);
	
	//test: Rook near wall
	stateString = 	"0 W\n" +
	".....\n" +
	".....\n" +
	".....\n" +
	"R....\n" +
	".....\n" +
	".....\n";
	testHelper(stateString);
	
	//test: Rook with friendly piece in sight
	stateString = 	"0 W\n" +
	".....\n" +
	".....\n" +
	".....\n" +
	"..P..\n" +
	".....\n" +
	"..R..\n";
	testHelper(stateString);
	
	//test: Rook with friendly piece in sight
	stateString = 	"0 W\n" +
	"..R..\n" +
	".....\n" +
	".....\n" +
	"..P..\n" +
	".....\n" +
	".....\n";
	testHelper(stateString);

	//test: Rook with friendly piece in sight
	stateString = 	"0 W\n" +
	".....\n" +
	".....\n" +
	".....\n" +
	"R.P..\n" +
	".....\n" +
	".....\n";
	testHelper(stateString);

	//test: Rook with friendly piece in sight
	stateString = 	"0 W\n" +
	".....\n" +
	".....\n" +
	".....\n" +
	"..P.R\n" +
	".....\n" +
	".....\n";
	testHelper(stateString);

	//test: Rook with friendly piece in sight
	stateString = 	"0 W\n" +
	".....\n" +
	".....\n" +
	".....\n" +
	"..p..\n" +
	".....\n" +
	"..R..\n";
	testHelper(stateString);
	
	//test: Rook with friendly piece in sight
	stateString = 	"0 W\n" +
	"..R..\n" +
	".....\n" +
	".....\n" +
	"..p..\n" +
	".....\n" +
	".....\n";
	testHelper(stateString);

	//test: Rook with friendly piece in sight
	stateString = 	"0 W\n" +
	".....\n" +
	".....\n" +
	".....\n" +
	"R.p..\n" +
	".....\n" +
	".....\n";
	testHelper(stateString);

	//test: Rook with friendly piece in sight
	stateString = 	"0 W\n" +
	".....\n" +
	".....\n" +
	".....\n" +
	"..p.R\n" +
	".....\n" +
	".....\n";
	testHelper(stateString);
	
	//test: Bishop only
	stateString = 	"0 W\n" +
	".....\n" +
	".....\n" +
	".....\n" +
	"..B..\n" +
	".....\n" +
	".....\n";
	testHelper(stateString);
	
	//test: Bishop in a corner (check diagonal)
	stateString = 	"0 W\n" +
	"B....\n" +
	".....\n" +
	".....\n" +
	".....\n" +
	".....\n" +
	".....\n";
	testHelper(stateString);
	
	//test: Bishop in a non-opposite corner (check other diagonal)
	stateString = 	"0 W\n" +
	"....B\n" +
	".....\n" +
	".....\n" +
	".....\n" +
	".....\n" +
	".....\n";
	testHelper(stateString);
	
	//test: Bishop in a non-opposite corner (check first diagonal from other side)
	stateString = 	"0 W\n" +
	".....\n" +
	".....\n" +
	".....\n" +
	".....\n" +
	".....\n" +
	"....B\n";
	testHelper(stateString);
	
	//test: Bishop in a non-opposite corner (check second diagonal from other side)
	stateString = 	"0 W\n" +
	".....\n" +
	".....\n" +
	".....\n" +
	".....\n" +
	".....\n" +
	"B....\n";
	testHelper(stateString);
	
	//test: Bishop with friendly piece in sight
	stateString = 	"0 W\n" +
	"B....\n" +
	".....\n" +
	"..P..\n" +
	".....\n" +
	".....\n" +
	".....\n";
	testHelper(stateString);
	
	//test: Bishop with friendly piece in sight 
	stateString = 	"0 W\n" +
	"....B\n" +
	".....\n" +
	"..P..\n" +
	".....\n" +
	".....\n" +
	".....\n";
	testHelper(stateString);

	//test: Bishop with friendly piece in sight
	stateString = 	"0 W\n" +
	".....\n" +
	".....\n" +
	".....\n" +
	"..P..\n" +
	".....\n" +
	"B....\n";
	testHelper(stateString);
	
	//test: Bishop with friendly piece in sight
	stateString = 	"0 W\n" +
	".....\n" +
	".....\n" +
	".....\n" +
	"..P..\n" +
	".....\n" +
	"....B\n";
	testHelper(stateString);

	//test: Bishop with enemy piece in sight
	stateString = 	"0 W\n" +
	"B....\n" +
	".....\n" +
	"..p..\n" +
	".....\n" +
	".....\n" +
	".....\n";
	testHelper(stateString);
	
	//test: Bishop with enemy piece in sight
	stateString = 	"0 W\n" +
	"....B\n" +
	".....\n" +
	"..p..\n" +
	".....\n" +
	".....\n" +
	".....\n";
	testHelper(stateString);
	
	//test: Bishop with enemy piece in sight
	stateString = 	"0 W\n" +
	".....\n" +
	".....\n" +
	".....\n" +
	"..p..\n" +
	".....\n" +
	"B....\n";
	testHelper(stateString);
		
	//test: Bishop with enemy piece in sight
	stateString = 	"0 W\n" +
	".....\n" +
	".....\n" +
	".....\n" +
	"..p..\n" +
	".....\n" +
	"....B\n";
	testHelper(stateString);
	
	//test: Knight only
	stateString = 	"0 W\n" +
	".....\n" +
	".....\n" +
	"..N..\n" +
	".....\n" +
	".....\n" +
	".....\n";
	testHelper(stateString);
	
	//test: Knight near wall
	stateString = 	"0 W\n" +
	".....\n" +
	".....\n" +
	"N....\n" +
	".....\n" +
	".....\n" +
	".....\n";
	testHelper(stateString);
	
	//test: Knight with friendly piece in sight
	stateString = 	"0 W\n" +
	".....\n" +
	"....P\n" +
	"..N..\n" +
	".....\n" +
	".....\n" +
	".....\n";
	testHelper(stateString);
	
	//test: Knight with enemy piece in sight
	stateString = 	"0 W\n" +
	".....\n" +
	"....r\n" +
	"..N..\n" +
	".....\n" +
	".....\n" +
	".....\n";
	testHelper(stateString);
	
	//test: Pawn only
	stateString = 	"0 W\n" +
	".....\n" +
	".....\n" +
	"..P..\n" +
	".....\n" +
	".....\n" +
	".....\n";
	testHelper(stateString);
	
	//test: Pawn near wall (note: this will never happen)
	// Correct behavior is to generate a PawnNotPromotedException.
	stateString = 	"0 W\n" +
	"..P..\n" +
	".....\n" +
	".....\n" +
	".....\n" +
	".....\n" +
	".....\n";
	testHelper(stateString);
	
	//test: Pawn with friendly piece in front
	stateString = 	"0 W\n" +
	".....\n" +
	"..P..\n" +
	"..P..\n" +
	".....\n" +
	".....\n" +
	".....\n";
	testHelper(stateString);
	
	
	//test: Pawn with enemy piece in front
	stateString = 	"0 W\n" +
	".....\n" +
	"..k..\n" +
	"..P..\n" +
	".....\n" +
	".....\n" +
	".....\n";
	testHelper(stateString);
	
	//test: Pawn with friendly piece in front to side
	stateString = 	"0 W\n" +
	".....\n" +
	"...P.\n" +
	"..P..\n" +
	".....\n" +
	".....\n" +
	".....\n";
	testHelper(stateString);
	
	//test: Pawn with enemy piece in front to side
	stateString = 	"0 W\n" +
	".....\n" +
	"...k.\n" +
	"..P..\n" +
	".....\n" +
	".....\n" +
	".....\n";
	testHelper(stateString);
	
	//test: Pawn with friendly piece in front to side
	stateString = 	"0 W\n" +
	".....\n" +
	".P...\n" +
	"..P..\n" +
	".....\n" +
	".....\n" +
	".....\n";
	testHelper(stateString);
	
	//test: Pawn with enemy piece in front to side
	stateString = 	"0 W\n" +
	".....\n" +
	".k...\n" +
	"..P..\n" +
	".....\n" +
	".....\n" +
	".....\n";
	testHelper(stateString);
	
	//test: weird case
	stateString = 	
	"5 W\n" +
	"kQbnr\n" +
	"..p.p\n" +
	"...p.\n" +
	".....\n" +
	"PP.PP\n" +
	"RNBQK\n";
	testHelper(stateString);

	
	}
}
